package org.bigbird.jackson;


import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import lombok.ToString;

import java.util.List;

/**
 * 验证 JsonAlias与JsonProperty 是否合并起作用
 * 验证通过确实合并也起作用
 */
public class ParamDto {

    public static void main(String[] args) throws JsonProcessingException {
        ParamDto2 paramDto2=new ParamDto2();
        paramDto2.setKey("12312321");
        ObjectMapper objectMapper=new ObjectMapper();
        String s = objectMapper.writeValueAsString(paramDto2);
        System.out.println(s);

        ParamDto2 paramDto21 = objectMapper.readValue(s, ParamDto2.class);
        System.out.println(paramDto21);

        String a = "[{\"tableName\":\"fpp_test_ka_oplk\",\"schemaName\":\"default\",\"topicName\":\"fpp_test_ka_oplk\",\"key\":{\"dataFormat\":\"json\",\"fields\":[{\"name\":\"kafka_key\",\"dataFormat\":\"LONG\",\"type\":\"BIGINT\",\"hidden\":\"false\"}]},\"message\":{\"dataFormat\":\"json\",\"fields\":[{\"name\":\"name\",\"mapping\":\"name\",\"type\":\"VARCHAR\"},{\"name\":\"address\",\"mapping\":\"address\",\"type\":\"VARCHAR\"}]}}]";

        ObjectMapper objectMapper2 = new ObjectMapper();
        List<Object> stringList = objectMapper2.readValue(a, new TypeReference<List<Object>>() {});

// 打印结果
        for (Object str : stringList) {
            System.out.println(str);
        }

    }


    @Data
    @ToString
    public static class ParamDto2{
        @JsonAlias({"key","name"})
        @JsonProperty("name")
        private String key;
    }
}
